function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
layui.use(['form','layer'], function () {

    var $ = layui.$, form = layui.form, layer=layui.layer;

    $(function () {
        var type = getUrlParam('type');
        if (type != null && type == '0') { //忘记密码
            $('#tel').removeAttr("readonly");//去除input元素的readonly属性
        } else { //修改密码
            LoginStatus();
            var userInfo = JSON.parse($.cookie('userInfo'));
            $('#tel').val(userInfo.tel);
            form.render();
        }
    })


    form.on('submit(btnSave)', function (data) {
        layer.load(2);
        var id = getUrlParam('id');
        var resetServices = '';
        if(id==1){
            resetServices = services;
        }else{
            resetServices = companyServices;
        }
        $.ajax({
            type: 'post', // 提交方式 get/post
            url: resetServices+"/user/reset/password/auth", // 需要提交的 url
            contentType:"application/json;charset=utf-8",
            xhrFields: {
                withCredentials: true
            }
            ,crossDomain: true
            ,data:JSON.stringify(data.field),
            success: function(res) {
                console.log(res);
                layer.closeAll('loading');
                if(res.status == '00200'){
                    layerMsg(res.message);
                    setTimeout(function() {
                        window.location.href="password-new.html?id="+id ;
                    }, 2000);

                }else{
                    layerMsg(res.message)
                }
            },fail:function () {
                layer.closeAll('loading');
            }
        })
        return false;
    });


});




